package com.lin.baby.boot.chapter3;

import com.lin.baby.boot.chapter1.service.CallSayHelloService;
import com.lin.baby.boot.chapter1.service.HelloService;
import com.lin.baby.boot.chapter3.config.ApplicationResourceConfig;
import com.lin.baby.boot.chapter3.config.ProfileConfig;
import com.lin.baby.boot.chapter3.service.HelloWordService;
import org.aspectj.weaver.ast.Call;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Class Desc
 *
 * @author WangYang
 * @version 1.0
 * @datetime 2016/10/13 19:57
 */
public class MainChapter3 {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.getEnvironment().setActiveProfiles("en");
        context.register(ApplicationResourceConfig.class, ProfileConfig.class);
        context.refresh();

        ApplicationResourceConfig config = context.getBean("elConfig", ApplicationResourceConfig.class);
        System.out.println(config.getOsName());
        System.out.println(config.getSystemName());
        System.out.println(config.getTitle());
        System.out.println(config.getRandomNumber());
        System.out.println(config.getEnvironment().getProperty("system.name"));

        CallSayHelloService callSayHelloService = context.getBean("callSayHelloService", CallSayHelloService.class);
        HelloWordService helloWordService = context.getBean("helloWordService", HelloWordService.class);
        helloWordService.hello("中国");
        context.close();
    }

}
